using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;

[WebService(Namespace = "http://schemas.rensoft.net/AccountsService/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AccountsService : System.Web.Services.WebService
{
    [WebMethod]
    public void Test() { }

    [WebMethod]
    public Account AccountCreate(string title, string code, AccountType types, string currency)
    {
        return Account.Create(title, code, types, currency);
    }

    [WebMethod]
    public bool AccountCheckCodeExists(string code)
    {
        return Account.CheckCodeExists(code);
    }

    [WebMethod]
    public Account AccountFetchById(int accountId)
    {
        return Account.Fetch(accountId);
    }

    [WebMethod]
    public List<Account> AccountFetchByType(AccountType types)
    {
        return Account.Fetch(types);
    }

    [WebMethod]
    public void AccountUpdateContactGuids(List<string> guidList, int accountId)
    {
        Account.UpdateContacts(guidList, accountId);
    }

    [WebMethod]
    public List<string> AccountFetchContactGuids(int accountId)
    {
        return Account.FetchContacts(accountId);
    }

    [WebMethod]
    public ClientAccountSnapshot ClientAccountSnapshotFetch(
        int accountId, int relativeInvoiceId, DateTime snapshotDate)
    {
        return ClientAccountSnapshot.Fetch(accountId, relativeInvoiceId, snapshotDate);
    }

    [WebMethod]
    public WebsiteService WebsiteCreate(string title, int accountId)
    {
        return WebsiteService.Create(title, accountId);
    }

    [WebMethod]
    public List<WebsiteService> WebsiteFetchAll()
    {
        return WebsiteService.Fetch();
    }

    [WebMethod]
    public MailboxService MailboxCreate(string title, string password, int accountId)
    {
        return MailboxService.Create(title, password, accountId);
    }

    [WebMethod]
    public List<MailboxService> MailboxFetchAll()
    {
        return MailboxService.Fetch();
    }

    [WebMethod]
    public DomainService DomainCreate(
        string title, DateTime registerDate, DateTime expiryDate, int accountId)
    {
        return DomainService.Create(title, registerDate, expiryDate, accountId);
    }

    [WebMethod]
    public List<DomainService> DomainFetchAll()
    {
        return DomainService.Fetch();
    }

    [WebMethod]
    public Invoice InvoiceCreate(
        string invoiceRef, 
        string recipientRef,
        List<InvoiceItem> invoiceItemList,
        DateTime invoiceDate,
        InvoiceType type,
        int accountId)
    {
        return Invoice.Create(
            invoiceRef, 
            recipientRef, 
            invoiceItemList,
            invoiceDate,
            type,
            accountId);
    }

    [WebMethod]
    public List<Invoice> InvoiceFetch(InvoiceType type)
    {
        return Invoice.Fetch(type);
    }

    [WebMethod]
    public List<Invoice> InvoiceFetchByAccountId(int accountId)
    {
        return Invoice.Fetch(accountId);
    }

    [WebMethod]
    public List<InvoiceItem> InvoiceItemFetch(int invoiceId)
    {
        return InvoiceItem.Fetch(invoiceId);
    }

    [WebMethod]
    public bool SettingExists(string key)
    {
        return Settings.Exists(key);
    }

    [WebMethod]
    public void SettingUpdate(string key, string value)
    {
        Settings.Update(key, value);
    }

    [WebMethod]
    public string SettingFetch(string key)
    {
        return Settings.Fetch(key);
    }

    [WebMethod]
    public Payment PaymentCreate(
        PaymentType type, 
        PaymentDirection direction, 
        decimal amount,
        DateTime paymentDate,
        string reference,
        int accountId)
    {
        return Payment.Create(type, direction, amount, paymentDate, reference, accountId);
    }

    [WebMethod]
    public List<Payment> PaymentFetchAll()
    {
        return Payment.Fetch();
    }

    [WebMethod]
    public List<Payment> PaymentFetchByAccountId(int accountId)
    {
        return Payment.Fetch(accountId);
    }

    [WebMethod]
    public Credit CreditCreate(
        CreditDirection direction,
        decimal amount,
        DateTime creditDate,
        string reference,
        string details,
        int accountId)
    {
        return Credit.Create(direction, amount, creditDate, details, reference, accountId);
    }

    [WebMethod]
    public List<Credit> CreditFetchAll()
    {
        return Credit.Fetch();
    }

    [WebMethod]
    public List<Credit> CreditFetchByAccountId(int accountId)
    {
        return Credit.Fetch(accountId);
    }
}